package com.gxlevi.math.algorithm;

/**
 * 换诺塔 - 分治算法
 */
public class Hanoitower {
    public static void main(String[] args) {
        hanoiTower(2, 'A', 'B', 'C');
    }

    //汉诺塔的移动方法
    //分治算法
    public static void hanoiTower(int num, char a, char b, char c) {
        if (num == 1) {
            System.out.println("将第一个盘从" + a + "->" + c);
        } else {
            hanoiTower(num - 1, a, c, b);
            System.out.printf("将第%d个盘从" + a + "->" + c + "\n", num);
            hanoiTower(num - 1, b, a, c);
        }
    }
}
